/*
 * AlloeMain.java
 *
 * Created on 09 January 2008, 16:57
 */
package nii.alloe.gui;

import javax.swing.*;
import javax.swing.table.*;
import java.io.*;
import java.util.*;
import java.text.*;
import nii.alloe.classify.*;
import nii.alloe.consist.*;
import nii.alloe.corpus.*;
import nii.alloe.corpus.pattern.*;
import nii.alloe.theory.*;
import nii.alloe.tools.process.AlloeProcess;
import nii.alloe.tools.process.AlloeProgressListener;
import weka.classifiers.*;
import weka.core.*;

/**
 *
 * @author  john
 */
public class AlloeMain extends javax.swing.JFrame {

    private Corpus corpus;
    private String corpusTextFile;
    private File corpusTermSetFile;
    private File corpusIndexFile;
    private CorpusLoader corpusLoader;
    private JFileChooser fileChooser;
    private CorpusLoaderProgressListener clProgListener;
    private PatternGeneratorListener pbListener;
    private FeatureVectorListener fvListener;
    private HashMap<String, File> termSetFileName;
    private HashMap<String, File> fvTermSetFileName;
    private boolean isTraining;
    private HashMap<String, PatternBuilder> patternBuilderProcess;
    private FeatureVectorFormer featureVectorProcess;
    private HashMap<String, PatternSet> patternSets;
    private HashMap<String, Boolean> lazyMatching;
    private DataSet dataSet;
    private Map<String, Classifier> classifierSet;
    private Logic logic;
    private ProbModelBuilder probModelBuilder;
    private Model model;
    private ConsistProblem consistProblem;
    private SparseMatrix matrix;
    private ConsistSolver consistSolver;
    private GrowingSolver growingSolver;
    private TermList standardTermList;
    private Model standardModel;
    private Model solvedModel;
    private HashMap<String, String> standardModelTermPairs;
    private PatternAdvancedDialog patternAdvancedDialog;

    /** Creates new form AlloeMain */
    public AlloeMain() {
        initComponents();
        corpusTextFile = null;
        corpusTermSetFile = corpusIndexFile = null;
        fileChooser = new JFileChooser();
        //thisForAnon = this;
        corpusDisplayTableModel = new CorpusTableModel();
        termSetFileName = new HashMap<String, File>();
        fvTermSetFileName = new HashMap<String, File>();
        patternBuilderProcess = new HashMap<String, PatternBuilder>();
        patternSets = new HashMap<String, PatternSet>();
        lazyMatching = new HashMap<String, Boolean>();
        classifierSet = new HashMap<String, Classifier>();
        standardModelTermPairs = new HashMap<String, String>();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        solverRadioGroup = new javax.swing.ButtonGroup();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        patternGenerationPolicy = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        openCorpusTextFile = new javax.swing.JButton();
        openCorpusTermSet = new javax.swing.JButton();
        textFileLabel = new javax.swing.JLabel();
        termSetLabel = new javax.swing.JLabel();
        indexerProgressMonitor = new nii.alloe.gui.ProcessMonitor();
        if(clProgListener == null)
        clProgListener = new CorpusLoaderProgressListener();
        indexerProgressMonitor.addExtraListener(clProgListener);
        indexLocationLabel = new javax.swing.JLabel();
        setIndexButton = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        contextSizeSpinner = new javax.swing.JSpinner();
        useSketchingCheck = new javax.swing.JCheckBox();
        maxSketchLabel = new javax.swing.JLabel();
        sketchSizeSpinner = new javax.swing.JSpinner();
        jPanel5 = new javax.swing.JPanel();
        openIndexedCorpus = new javax.swing.JButton();
        corpusDisplayScroll = new javax.swing.JScrollPane();
        corpusDisplay = new javax.swing.JTable();
        corpusTotalLabel = new javax.swing.JLabel();
        viewContextsButton = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        termPairSetLabel = new javax.swing.JLabel();
        openTermPairSet = new javax.swing.JButton();
        patternGeneratorRelationship = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        patternGeneratorProgressMonitor = new nii.alloe.gui.ProcessMonitor();
        if(pbListener == null)
        pbListener = new PatternGeneratorListener();
        patternGeneratorProgressMonitor.addExtraListener(pbListener);
        patternBuilderMetric = new javax.swing.JComboBox();
        metricLabel = new javax.swing.JLabel();
        patternAdvanced = new javax.swing.JButton();
        allPatterns = new javax.swing.JRadioButton();
        bestPatternSet = new javax.swing.JRadioButton();
        bestPatternSetSize = new javax.swing.JSpinner();
        jPanel7 = new javax.swing.JPanel();
        patternViewerRelationshipLabel = new javax.swing.JLabel();
        patternViewerRelationship = new javax.swing.JComboBox();
        openPatternSet = new javax.swing.JButton();
        savePatternSet = new javax.swing.JButton();
        totalPatternsLabel = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        patternTable = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        featureVectorPatternSet = new javax.swing.JComboBox();
        openDataSet = new javax.swing.JButton();
        saveDataSet = new javax.swing.JButton();
        featureVectorFormerMonitor = new nii.alloe.gui.ProcessMonitor();
        featureVectorFormerMonitor.addProcessMonitorListener(new FVPMListener());
        featureVectorTermPairLabel = new javax.swing.JLabel();
        featureOpenTermPairs = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        featureVectorRelationship = new javax.swing.JTextField();
        isTrainingCheck = new javax.swing.JCheckBox();
        useLazyMatching = new javax.swing.JCheckBox();
        jPanel9 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        wekaOutput = new javax.swing.JTextArea();
        classifier = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        classifierParameters = new javax.swing.JTextField();
        saveClassifierButton = new javax.swing.JButton();
        openClassifierButton = new javax.swing.JButton();
        startTrainingButton = new javax.swing.JButton();
        jPanel11 = new javax.swing.JPanel();
        jPanel10 = new javax.swing.JPanel();
        probModelBuilderMonitor = new nii.alloe.gui.ProcessMonitor();
        logicLabel = new javax.swing.JLabel();
        openLogic = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        logicConnectionTable = new javax.swing.JTable();
        modelRelationship = new javax.swing.JComboBox();
        saveModel = new javax.swing.JButton();
        openModel = new javax.swing.JButton();
        modelRelationShipLabel = new javax.swing.JLabel();
        visualizeModel = new javax.swing.JButton();
        modelLinksLabel = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        logicDescription = new javax.swing.JTextArea();
        saveLogicButton = new javax.swing.JButton();
        processLogicButton = new javax.swing.JButton();
        jPanel12 = new javax.swing.JPanel();
        useStandardSolver = new javax.swing.JRadioButton();
        useGrowingSolver = new javax.swing.JRadioButton();
        jPanel13 = new javax.swing.JPanel();
        pmRowsLabel = new javax.swing.JLabel();
        pmColsLabel = new javax.swing.JLabel();
        pmElemsLabel = new javax.swing.JLabel();
        problemMatrixMonitor = new nii.alloe.gui.ProcessMonitor();
        saveProblemMatrix = new javax.swing.JButton();
        openProblemMatrix = new javax.swing.JButton();
        jPanel14 = new javax.swing.JPanel();
        solverMonitor = new nii.alloe.gui.ProcessMonitor();
        solverAddedLabel = new javax.swing.JLabel();
        solverRemovedLabel = new javax.swing.JLabel();
        solverScoreLabel = new javax.swing.JLabel();
        jPanel15 = new javax.swing.JPanel();
        confusionMatrixPre = new javax.swing.JTable();
        standardRelationship = new javax.swing.JComboBox();
        standardOpenTermPairs = new javax.swing.JButton();
        standardTermPairLabel = new javax.swing.JLabel();
        saveStandardModel = new javax.swing.JButton();
        openStandardModel = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        precisionPreLabel = new javax.swing.JLabel();
        recallPreLabel = new javax.swing.JLabel();
        fMeasurePreLabel = new javax.swing.JLabel();
        standardTermSetLabel = new javax.swing.JLabel();
        standardOpenTermSet = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        confusionMatrixPost = new javax.swing.JTable();
        precisionPostLabel = new javax.swing.JLabel();
        recallPostLabel = new javax.swing.JLabel();
        fMeasurePostLabel = new javax.swing.JLabel();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane5.setViewportView(jTable1);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Alloe");

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Corpus Indexer"));

        openCorpusTextFile.setText("Open Text File");
        openCorpusTextFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openCorpusTextFileActionPerformed(evt);
            }
        });

        openCorpusTermSet.setText("Open Term Set");
        openCorpusTermSet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openCorpusTermSetActionPerformed(evt);
            }
        });

        textFileLabel.setText("Text File: Not Loaded");

        termSetLabel.setText("Term Set: Not Loaded");

        indexerProgressMonitor.setProcessCompletedText("Corpus loaded");
        indexerProgressMonitor.setProcessNotStartedText("Corpus not loaded");

        indexLocationLabel.setText("Index Location: Not Loaded");

        setIndexButton.setText("Set Index");
        setIndexButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                setIndexButtonActionPerformed(evt);
            }
        });

        jLabel7.setText("Context Size:");

        contextSizeSpinner.setModel(new SpinnerNumberModel(0,0,Integer.MAX_VALUE,1));
        contextSizeSpinner.setValue(3);
        contextSizeSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                contextSizeSpinnerStateChanged(evt);
            }
        });

        useSketchingCheck.setText("Use Sketching");
        useSketchingCheck.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        useSketchingCheck.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                useSketchingCheckActionPerformed(evt);
            }
        });

        maxSketchLabel.setText("Max Sketch");
        maxSketchLabel.setEnabled(false);

        sketchSizeSpinner.setModel(new SpinnerNumberModel(0,0,Integer.MAX_VALUE,1));
        sketchSizeSpinner.setEnabled(false);
        sketchSizeSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                sketchSizeSpinnerStateChanged(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(termSetLabel)
                            .addComponent(textFileLabel)
                            .addComponent(indexLocationLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 168, Short.MAX_VALUE)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(setIndexButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(openCorpusTextFile, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(openCorpusTermSet, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(contextSizeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
                        .addComponent(useSketchingCheck)
                        .addGap(32, 32, 32)
                        .addComponent(maxSketchLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sketchSizeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(indexerProgressMonitor, javax.swing.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFileLabel)
                    .addComponent(openCorpusTextFile))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(openCorpusTermSet)
                    .addComponent(termSetLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(indexLocationLabel)
                    .addComponent(setIndexButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(maxSketchLabel)
                    .addComponent(sketchSizeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(useSketchingCheck)
                    .addComponent(contextSizeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(indexerProgressMonitor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Corpus"));

        openIndexedCorpus.setText("Open Corpus");
        openIndexedCorpus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openIndexedCorpusActionPerformed(evt);
            }
        });

        corpusDisplay.setAutoCreateRowSorter(true);
        corpusDisplay.setModel(getCorpusDisplayTableModel());
        corpusDisplayScroll.setViewportView(corpusDisplay);

        corpusTotalLabel.setText("Total Contexts: 0");

        viewContextsButton.setText("View Contexts");
        viewContextsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewContextsButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(corpusDisplayScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(openIndexedCorpus)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(viewContextsButton)
                        .addGap(57, 57, 57)
                        .addComponent(corpusTotalLabel)))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(openIndexedCorpus)
                    .addComponent(corpusTotalLabel)
                    .addComponent(viewContextsButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(corpusDisplayScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Corpus", jPanel1);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Generate Patterns"));

        termPairSetLabel.setText("Term Pair Set:");
        termPairSetLabel.setEnabled(false);

        openTermPairSet.setText("Open Term Pair Set");
        openTermPairSet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openTermPairSetActionPerformed(evt);
            }
        });

        patternGeneratorRelationship.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "", "New..." }));
        patternGeneratorRelationship.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                patternGeneratorRelationshipActionPerformed(evt);
            }
        });

        jLabel2.setText("Relationship:");

        patternGeneratorProgressMonitor.setProcessCompletedText("Pattern Set Generated");
        patternGeneratorProgressMonitor.setProcessNotStartedText("Ready");

        patternBuilderMetric.setModel(new DefaultComboBoxModel(PatternMetricFactory.getPatternMetrics()));
        patternBuilderMetric.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                patternBuilderMetricActionPerformed(evt);
            }
        });

        metricLabel.setText("Metric::");

        patternAdvanced.setText("Advanced");
        patternAdvanced.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                patternAdvancedActionPerformed(evt);
            }
        });

        patternGenerationPolicy.add(allPatterns);
        allPatterns.setSelected(true);
        allPatterns.setText("All Patterns");
        allPatterns.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        allPatterns.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                allPatternsActionPerformed(evt);
            }
        });

        patternGenerationPolicy.add(bestPatternSet);
        bestPatternSet.setText("Best Set of size:");
        bestPatternSet.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        bestPatternSet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bestPatternSetActionPerformed(evt);
            }
        });

        bestPatternSetSize.setModel(new SpinnerNumberModel(0,0,Integer.MAX_VALUE,1));
        bestPatternSetSize.setEnabled(false);
        bestPatternSetSize.setValue((Integer)100);
        bestPatternSetSize.setVerifyInputWhenFocusTarget(false);
        bestPatternSetSize.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                bestPatternSetSizeStateChanged(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(patternGeneratorRelationship, 0, 346, Short.MAX_VALUE))
                    .addComponent(patternGeneratorProgressMonitor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(metricLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(patternBuilderMetric, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 62, Short.MAX_VALUE)
                        .addComponent(patternAdvanced))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addComponent(allPatterns)
                                .addGap(53, 53, 53)
                                .addComponent(bestPatternSet))
                            .addComponent(termPairSetLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(bestPatternSetSize)
                            .addComponent(openTermPairSet, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(patternGeneratorRelationship, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(openTermPairSet)
                    .addComponent(termPairSetLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(allPatterns)
                    .addComponent(bestPatternSetSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bestPatternSet))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(metricLabel)
                    .addComponent(patternAdvanced)
                    .addComponent(patternBuilderMetric, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(patternGeneratorProgressMonitor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Pattern Sets"));

        patternViewerRelationshipLabel.setText("Relationship:");
        patternViewerRelationshipLabel.setEnabled(false);

        patternViewerRelationship.setEnabled(false);
        patternViewerRelationship.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                patternViewerRelationshipActionPerformed(evt);
            }
        });

        openPatternSet.setText("Open Pattern Set");
        openPatternSet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openPatternSetActionPerformed(evt);
            }
        });

        savePatternSet.setText("Save Pattern Set");
        savePatternSet.setEnabled(false);
        savePatternSet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                savePatternSetActionPerformed(evt);
            }
        });

        totalPatternsLabel.setText("Total Patterns:");

        patternTable.setAutoCreateRowSorter(true);
        patternTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Pattern", "Score"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(patternTable);

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel7Layout.createSequentialGroup()
                        .addComponent(patternViewerRelationshipLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(patternViewerRelationship, 0, 346, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel7Layout.createSequentialGroup()
                        .addComponent(openPatternSet)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(savePatternSet)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(totalPatternsLabel)))
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(patternViewerRelationshipLabel)
                    .addComponent(patternViewerRelationship, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(openPatternSet)
                    .addComponent(savePatternSet)
                    .addComponent(totalPatternsLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Patterns", jPanel2);

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder("Feature Vector Former"));

        jLabel1.setText("Pattern Set:");

        featureVectorPatternSet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                featureVectorPatternSetActionPerformed(evt);
            }
        });

        openDataSet.setText("Open Vectors");
        openDataSet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openDataSetActionPerformed(evt);
            }
        });

        saveDataSet.setText("Save Vectors");
        saveDataSet.setEnabled(false);
        saveDataSet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveDataSetActionPerformed(evt);
            }
        });

        featureVectorFormerMonitor.setProcessCompletedText("Feature Vectors Loaded");
        featureVectorFormerMonitor.setProcessNotStartedText("Feature Vectors not Loaded");

        featureVectorTermPairLabel.setText("Term Pair Set:");

        featureOpenTermPairs.setText("Open Term Pair Set");
        featureOpenTermPairs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                featureOpenTermPairsActionPerformed(evt);
            }
        });

        jLabel4.setText("Relationship:");

        isTrainingCheck.setSelected(true);
        isTrainingCheck.setText("Training");
        isTrainingCheck.setToolTipText("Generate class data");
        isTrainingCheck.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        isTrainingCheck.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                isTrainingCheckActionPerformed(evt);
            }
        });

        useLazyMatching.setText("Lazy Matching");
        useLazyMatching.setToolTipText("Use lazy matching (drop any wildcard)");
        useLazyMatching.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        useLazyMatching.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                useLazyMatchingActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(featureVectorFormerMonitor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(23, 23, 23)
                        .addComponent(featureVectorPatternSet, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(openDataSet)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(saveDataSet))
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(featureVectorRelationship, javax.swing.GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(isTrainingCheck))
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(featureVectorTermPairLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 107, Short.MAX_VALUE)
                        .addComponent(featureOpenTermPairs)
                        .addGap(3, 3, 3)
                        .addComponent(useLazyMatching)))
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(openDataSet)
                    .addComponent(saveDataSet)
                    .addComponent(featureVectorPatternSet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(isTrainingCheck)
                    .addComponent(featureVectorRelationship, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(featureVectorTermPairLabel)
                    .addComponent(featureOpenTermPairs)
                    .addComponent(useLazyMatching))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(featureVectorFormerMonitor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder("Train Classifier"));

        wekaOutput.setColumns(20);
        wekaOutput.setEditable(false);
        wekaOutput.setRows(5);
        wekaOutput.setToolTipText("WEKA Output");
        jScrollPane2.setViewportView(wekaOutput);

        classifier.setModel(new DefaultComboBoxModel(getClassifierNames()));
        classifier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                classifierActionPerformed(evt);
            }
        });

        jLabel5.setText("Classifier:");

        jLabel6.setText("Parameters:");

        saveClassifierButton.setText("Save Classifier");
        saveClassifierButton.setEnabled(false);
        saveClassifierButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveClassifierButtonActionPerformed(evt);
            }
        });

        openClassifierButton.setText("Open Classifier");
        openClassifierButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openClassifierButtonActionPerformed(evt);
            }
        });

        startTrainingButton.setText("Start Training");
        startTrainingButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startTrainingButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(classifier, 0, 108, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(classifierParameters, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(startTrainingButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 135, Short.MAX_VALUE)
                        .addComponent(openClassifierButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(saveClassifierButton)))
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(classifierParameters, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(classifier, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saveClassifierButton)
                    .addComponent(openClassifierButton)
                    .addComponent(startTrainingButton))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Classification", jPanel3);

        jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder("Create Model"));

        probModelBuilderMonitor.addExtraListener(new ModelProcessListener());

        logicLabel.setText("Logic");

        openLogic.setText("Open Logic");
        openLogic.setToolTipText("Open a logic from a file");
        openLogic.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openLogicActionPerformed(evt);
            }
        });

        logicConnectionTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Logic Relation", "Feature Vector", "Classifier"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane3.setViewportView(logicConnectionTable);

        modelRelationship.setEnabled(false);
        modelRelationship.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modelRelationshipActionPerformed(evt);
            }
        });

        saveModel.setText("Save Model");
        saveModel.setEnabled(false);
        saveModel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveModelActionPerformed(evt);
            }
        });

        openModel.setText("Open Model");
        openModel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openModelActionPerformed(evt);
            }
        });

        modelRelationShipLabel.setText("Relationship:");
        modelRelationShipLabel.setEnabled(false);

        visualizeModel.setText("Visualize");
        visualizeModel.setEnabled(false);

        modelLinksLabel.setText("Model Links:");
        modelLinksLabel.setEnabled(false);

        logicDescription.setColumns(20);
        logicDescription.setRows(5);
        jScrollPane4.setViewportView(logicDescription);

        saveLogicButton.setText("Save Logic");
        saveLogicButton.setEnabled(false);
        saveLogicButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveLogicButtonActionPerformed(evt);
            }
        });

        processLogicButton.setText("Process Logic");
        processLogicButton.setToolTipText("Load the logic as above");
        processLogicButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                processLogicButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addComponent(logicLabel)
                        .addGap(459, 459, 459))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel10Layout.createSequentialGroup()
                        .addComponent(processLogicButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(openLogic)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(saveLogicButton)
                        .addContainerGap())
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel10Layout.createSequentialGroup()
                                .addComponent(modelLinksLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 334, Short.MAX_VALUE)
                                .addComponent(visualizeModel))
                            .addGroup(jPanel10Layout.createSequentialGroup()
                                .addComponent(modelRelationShipLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(modelRelationship, 0, 387, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel10Layout.createSequentialGroup()
                                .addComponent(probModelBuilderMonitor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(29, 29, 29)))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel10Layout.createSequentialGroup()
                        .addComponent(openModel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(saveModel)
                        .addContainerGap())))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addComponent(logicLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saveLogicButton)
                    .addComponent(openLogic)
                    .addComponent(processLogicButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(probModelBuilderMonitor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(modelRelationShipLabel)
                    .addComponent(modelRelationship, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(visualizeModel)
                    .addComponent(modelLinksLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saveModel)
                    .addComponent(openModel))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Model", jPanel11);

        solverRadioGroup.add(useStandardSolver);
        useStandardSolver.setSelected(true);
        useStandardSolver.setText("Standard Solver");
        useStandardSolver.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        useStandardSolver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                useStandardSolverActionPerformed(evt);
            }
        });

        solverRadioGroup.add(useGrowingSolver);
        useGrowingSolver.setText("Growing Solver");
        useGrowingSolver.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        useGrowingSolver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                useGrowingSolverActionPerformed(evt);
            }
        });

        jPanel13.setBorder(javax.swing.BorderFactory.createTitledBorder("Problem Matrix"));

        pmRowsLabel.setText("Rows:               ");
        pmRowsLabel.setEnabled(false);

        pmColsLabel.setText("Columns:               ");
        pmColsLabel.setEnabled(false);

        pmElemsLabel.setText("Elements:               ");
        pmElemsLabel.setEnabled(false);

        problemMatrixMonitor.setProcessCompletedText("Matrix complete");
        problemMatrixMonitor.setProcessNotStartedText("Matrix not formed");

        saveProblemMatrix.setText("Save Matrix");
        saveProblemMatrix.setEnabled(false);
        saveProblemMatrix.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveProblemMatrixActionPerformed(evt);
            }
        });

        openProblemMatrix.setText("Open Matrix");
        openProblemMatrix.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openProblemMatrixActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel13Layout = new javax.swing.GroupLayout(jPanel13);
        jPanel13.setLayout(jPanel13Layout);
        jPanel13Layout.setHorizontalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel13Layout.createSequentialGroup()
                .addContainerGap(281, Short.MAX_VALUE)
                .addComponent(openProblemMatrix)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(saveProblemMatrix)
                .addContainerGap())
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(problemMatrixMonitor, javax.swing.GroupLayout.PREFERRED_SIZE, 438, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel13Layout.createSequentialGroup()
                        .addComponent(pmRowsLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pmColsLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pmElemsLabel)))
                .addContainerGap(25, Short.MAX_VALUE))
        );
        jPanel13Layout.setVerticalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(pmRowsLabel)
                    .addComponent(pmColsLabel)
                    .addComponent(pmElemsLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(problemMatrixMonitor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saveProblemMatrix)
                    .addComponent(openProblemMatrix))
                .addContainerGap())
        );

        jPanel14.setBorder(javax.swing.BorderFactory.createTitledBorder("Solver"));

        solverMonitor.setProcessCompletedText("Solved");
        solverMonitor.setProcessNotStartedText("Solver not started");

        solverAddedLabel.setText("Added:              ");
        solverAddedLabel.setEnabled(false);

        solverRemovedLabel.setText("Removed:             ");
        solverRemovedLabel.setEnabled(false);

        solverScoreLabel.setText("Score:             ");
        solverScoreLabel.setEnabled(false);

        javax.swing.GroupLayout jPanel14Layout = new javax.swing.GroupLayout(jPanel14);
        jPanel14.setLayout(jPanel14Layout);
        jPanel14Layout.setHorizontalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(solverAddedLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(solverRemovedLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(solverScoreLabel)
                .addContainerGap(141, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel14Layout.createSequentialGroup()
                .addContainerGap(36, Short.MAX_VALUE)
                .addComponent(solverMonitor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel14Layout.setVerticalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(solverAddedLabel)
                    .addComponent(solverRemovedLabel)
                    .addComponent(solverScoreLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(solverMonitor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel15.setBorder(javax.swing.BorderFactory.createTitledBorder("Standard Model"));

        confusionMatrixPre.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        confusionMatrixPre.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null}
            },
            new String [] {
                "Title 1", "Title 2"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });

        standardOpenTermPairs.setText("Open Term Pairs");
        standardOpenTermPairs.setEnabled(false);
        standardOpenTermPairs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                standardOpenTermPairsActionPerformed(evt);
            }
        });

        standardTermPairLabel.setText("Term Pair File:");
        standardTermPairLabel.setEnabled(false);

        saveStandardModel.setText("Save Model");
        saveStandardModel.setEnabled(false);
        saveStandardModel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveStandardModelActionPerformed(evt);
            }
        });

        openStandardModel.setText("Open Model");

        jLabel8.setText("Confusion Matrix (Before Solver)");

        precisionPreLabel.setText("Precision:");
        precisionPreLabel.setEnabled(false);

        recallPreLabel.setText("Recall:");
        recallPreLabel.setEnabled(false);

        fMeasurePreLabel.setText("F-Measure:");
        fMeasurePreLabel.setEnabled(false);

        standardTermSetLabel.setText("Term Set:");

        standardOpenTermSet.setText("Open Term Set");
        standardOpenTermSet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                standardOpenTermSetActionPerformed(evt);
            }
        });

        jLabel9.setText("Confusion Matrix (After Solver)");

        confusionMatrixPost.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        confusionMatrixPost.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null}
            },
            new String [] {
                "Title 1", "Title 2"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });

        precisionPostLabel.setText("Precision:");
        precisionPostLabel.setEnabled(false);

        recallPostLabel.setText("Recall:");
        recallPostLabel.setEnabled(false);

        fMeasurePostLabel.setText("F-Measure:");
        fMeasurePostLabel.setEnabled(false);

        javax.swing.GroupLayout jPanel15Layout = new javax.swing.GroupLayout(jPanel15);
        jPanel15.setLayout(jPanel15Layout);
        jPanel15Layout.setHorizontalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel15Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel15Layout.createSequentialGroup()
                        .addComponent(standardTermSetLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 279, Short.MAX_VALUE)
                        .addComponent(standardOpenTermSet))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel15Layout.createSequentialGroup()
                        .addComponent(standardRelationship, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(standardTermPairLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 113, Short.MAX_VALUE)
                        .addComponent(standardOpenTermPairs))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel15Layout.createSequentialGroup()
                        .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(confusionMatrixPre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(precisionPreLabel)
                            .addComponent(recallPreLabel)
                            .addComponent(fMeasurePreLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
                        .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(fMeasurePostLabel)
                            .addComponent(recallPostLabel)
                            .addComponent(precisionPostLabel)
                            .addComponent(confusionMatrixPost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel15Layout.createSequentialGroup()
                                .addComponent(openStandardModel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(saveStandardModel))
                            .addComponent(jLabel9))))
                .addContainerGap())
        );
        jPanel15Layout.setVerticalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel15Layout.createSequentialGroup()
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(standardOpenTermSet)
                    .addComponent(standardTermSetLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(standardOpenTermPairs)
                    .addComponent(standardRelationship, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(standardTermPairLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saveStandardModel)
                    .addComponent(openStandardModel))
                .addGap(12, 12, 12)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(confusionMatrixPre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(confusionMatrixPost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(precisionPreLabel)
                    .addComponent(precisionPostLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(recallPreLabel)
                    .addComponent(recallPostLabel))
                .addGap(7, 7, 7)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fMeasurePreLabel)
                    .addComponent(fMeasurePostLabel))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel12Layout = new javax.swing.GroupLayout(jPanel12);
        jPanel12.setLayout(jPanel12Layout);
        jPanel12Layout.setHorizontalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel12Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel15, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel14, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel13, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel12Layout.createSequentialGroup()
                        .addComponent(useStandardSolver)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(useGrowingSolver)))
                .addContainerGap())
        );
        jPanel12Layout.setVerticalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel12Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(useStandardSolver)
                    .addComponent(useGrowingSolver))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel15, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Consistency", jPanel12);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 519, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 585, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void bestPatternSetSizeStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_bestPatternSetSizeStateChanged
        if (patternAdvancedDialog != null) {
            patternAdvancedDialog.setPatternSetSize((Integer) bestPatternSetSize.getValue());
        }
        String name = patternGeneratorRelationship.getSelectedItem().toString();
        if (patternBuilderProcess.get(name) != null) {
            patternBuilderProcess.get(name).setMaxPatterns((Integer) bestPatternSetSize.getValue());
        }
    }//GEN-LAST:event_bestPatternSetSizeStateChanged

    private void bestPatternSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bestPatternSetActionPerformed
        metricLabel.setEnabled(false);
        patternBuilderMetric.setEnabled(false);
        bestPatternSetSize.setEnabled(true);
        String name = patternGeneratorRelationship.getSelectedItem().toString();
        if (patternBuilderProcess.get(name) != null &&
                !(patternBuilderProcess.get(name) instanceof PatternSetBuilder)) {
            initPatternBuilderProcess(name, true);

        }
    }//GEN-LAST:event_bestPatternSetActionPerformed

    private void allPatternsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allPatternsActionPerformed
        metricLabel.setEnabled(true);
        patternBuilderMetric.setEnabled(true);
        bestPatternSetSize.setEnabled(false);
        String name = patternGeneratorRelationship.getSelectedItem().toString();
        if (patternBuilderProcess.get(name) != null &&
                patternBuilderProcess.get(name) instanceof PatternSetBuilder) {
            initPatternBuilderProcess(name, false);
        }
    }//GEN-LAST:event_allPatternsActionPerformed

    private void sketchSizeSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_sketchSizeSpinnerStateChanged
        if (corpusLoader != null) {
            corpusLoader.setMaxSketchSize((Integer) sketchSizeSpinner.getValue());
        }
    }//GEN-LAST:event_sketchSizeSpinnerStateChanged

    private void contextSizeSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_contextSizeSpinnerStateChanged
        if (corpusLoader != null) {
            corpusLoader.setContextSize((Integer) contextSizeSpinner.getValue());
        }
    }//GEN-LAST:event_contextSizeSpinnerStateChanged

    private void useSketchingCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useSketchingCheckActionPerformed
        maxSketchLabel.setEnabled(useSketchingCheck.isSelected());
        sketchSizeSpinner.setEnabled(useSketchingCheck.isSelected());
        if (corpusLoader != null) {
            if (useSketchingCheck.isSelected()) {
                corpusLoader.setMaxSketchSize((Integer) sketchSizeSpinner.getValue());
            } else {
                corpusLoader.setMaxSketchSize(-1);
            }
        }
    }//GEN-LAST:event_useSketchingCheckActionPerformed

    private void useLazyMatchingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useLazyMatchingActionPerformed
        String pat = featureVectorPatternSet.getSelectedItem().toString();
        if (featureVectorProcess != null) {
            featureVectorProcess.setLazyMatching(useLazyMatching.isSelected());
        }
        lazyMatching.put(pat, useLazyMatching.isSelected());
    }//GEN-LAST:event_useLazyMatchingActionPerformed

    private void patternAdvancedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_patternAdvancedActionPerformed
        if (patternAdvancedDialog == null) {
            patternAdvancedDialog = new PatternAdvancedDialog(this, true);
        }
        patternAdvancedDialog.setPatternBuilder(patternBuilderProcess.get(patternGeneratorRelationship.getSelectedItem().toString()));
        patternAdvancedDialog.setPatternSet(patternSets.get(patternViewerRelationship.getSelectedItem().toString()));
        patternAdvancedDialog.setPatternSetSize((Integer) bestPatternSetSize.getValue());
        patternAdvancedDialog.setVisible(true);
        bestPatternSetSize.setValue((Integer) patternAdvancedDialog.getPatternSetSize());
    }//GEN-LAST:event_patternAdvancedActionPerformed

    private void useStandardSolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useStandardSolverActionPerformed
        pmRowsLabel.setEnabled(matrix != null);
        pmColsLabel.setEnabled(matrix != null);
        pmElemsLabel.setEnabled(matrix != null);
        problemMatrixMonitor.setEnabled(true);
        saveProblemMatrix.setEnabled(true);
        openProblemMatrix.setEnabled(false);
        prepareProblemMatrix();
        if (matrix != null) {
            solverMonitor.setProcess(consistSolver);
        }
    }//GEN-LAST:event_useStandardSolverActionPerformed

    private void useGrowingSolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useGrowingSolverActionPerformed
        pmRowsLabel.setEnabled(false);
        pmColsLabel.setEnabled(false);
        pmElemsLabel.setEnabled(false);
        problemMatrixMonitor.setEnabled(false);
        saveProblemMatrix.setEnabled(false);
        openProblemMatrix.setEnabled(false);
        prepareProblemMatrix();
    }//GEN-LAST:event_useGrowingSolverActionPerformed

    private void onStandardModelLoad() {
        saveStandardModel.setEnabled(true);
        if (model != null) {
            int[] comp = model.computeComparison(standardModel);
            Integer[][] conf = new Integer[2][2];
            conf[0][0] = comp[0];
            conf[0][1] = comp[1];
            conf[1][0] = comp[2];
            String[] name = {"true", "false"};
            confusionMatrixPre.setModel(new DefaultTableModel(conf, name));
            precisionPreLabel.setText("Precision: " + ((double) comp[0] / (double) (comp[0] + comp[1])));
            precisionPreLabel.setEnabled(true);
            recallPreLabel.setText("Recall: " + ((double) comp[0] / (double) (comp[0] + comp[2])));
            recallPreLabel.setEnabled(true);
            fMeasurePreLabel.setText("F-Measure: " + ((double) (2 * comp[0]) / (double) (2 * comp[0] + comp[1] + comp[2])));
            fMeasurePreLabel.setEnabled(true);
        }
        if (solvedModel != null) {
            int[] comp = solvedModel.computeComparison(standardModel);
            Integer[][] conf = new Integer[2][2];
            conf[0][0] = comp[0];
            conf[0][1] = comp[1];
            conf[1][0] = comp[2];
            String[] name = {"true", "false"};
            confusionMatrixPost.setModel(new DefaultTableModel(conf, name));
            precisionPostLabel.setText("Precision: " + ((double) comp[0] / (double) (comp[0] + comp[1])));
            precisionPostLabel.setEnabled(true);
            recallPostLabel.setText("Recall: " + ((double) comp[0] / (double) (comp[0] + comp[2])));
            recallPostLabel.setEnabled(true);
            fMeasurePostLabel.setText("F-Measure: " + ((double) (2 * comp[0]) / (double) (2 * comp[0] + comp[1] + comp[2])));
            fMeasurePostLabel.setEnabled(true);
        }
    }

    private void standardOpenTermPairsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_standardOpenTermPairsActionPerformed
        if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            try {
                ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileChooser.getSelectedFile()));
                Object o = ois.readObject();
                if (!(o instanceof TermPairSet)) {
                    JOptionPane.showMessageDialog(this, "Invalid Format", "Could not open term pair set", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                TermPairSet tps = (TermPairSet) o;
                standardModel.setGraphAs(standardRelationship.getSelectedItem().toString(),
                        tps, standardTermList);
                standardModelTermPairs.put(standardRelationship.getSelectedItem().toString(), fileChooser.getSelectedFile().getName());
                Iterator<String> smtpIter = standardModelTermPairs.values().iterator();
                while (smtpIter.hasNext()) {
                    if (smtpIter.next().equals("")) {
                        return;
                    }
                }
                onStandardModelLoad();
            } catch (IOException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open term pair set", JOptionPane.ERROR_MESSAGE);
            } catch (ClassNotFoundException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open term pair set", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_standardOpenTermPairsActionPerformed

    private void standardOpenTermSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_standardOpenTermSetActionPerformed
        if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            try {
                ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileChooser.getSelectedFile()));
                Object o = ois.readObject();
                if (!(o instanceof TermList)) {
                    JOptionPane.showMessageDialog(this, "Invalid Format", "Could not open term set", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                standardTermList = (TermList) o;
                standardTermSetLabel.setText("Term Set: " + fileChooser.getSelectedFile().getName());
            } catch (IOException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open term set", JOptionPane.ERROR_MESSAGE);
            } catch (ClassNotFoundException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open term set", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_standardOpenTermSetActionPerformed

    private void saveStandardModelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveStandardModelActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_saveStandardModelActionPerformed

    private void openProblemMatrixActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openProblemMatrixActionPerformed
        if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            try {
                ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileChooser.getSelectedFile()));
                Object o = ois.readObject();
                if (!(o instanceof SparseMatrix)) {
                    JOptionPane.showMessageDialog(this, "Invalid format", "Could not open matrix", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                matrix = (SparseMatrix) o;
                onLoadMatrix();
            } catch (IOException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open matrix", JOptionPane.ERROR_MESSAGE);
            } catch (ClassNotFoundException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open matrix", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_openProblemMatrixActionPerformed

    private void saveProblemMatrixActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveProblemMatrixActionPerformed
        if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
            try {
                ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileChooser.getSelectedFile()));
                oos.writeObject(matrix);
                oos.close();
            } catch (IOException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not save matrix", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_saveProblemMatrixActionPerformed

    private void onSolve() {
        if (model == null) {
            return;
        }
        TreeSet<Integer> soln, added, removed;
        double cost;
        if (useStandardSolver.isSelected()) {
            soln = consistSolver.soln;
            cost = consistSolver.cost;
            added = (TreeSet<Integer>) soln.clone();
            removed = (TreeSet<Integer>) added.clone();
            added.removeAll(model);
            removed.retainAll(model);
        } else {
            added = new TreeSet<Integer>(growingSolver.soln);
            added.removeAll(model);
            removed = new TreeSet<Integer>(model);
            removed.removeAll(growingSolver.soln);
            cost = growingSolver.cost;
        }
        solverAddedLabel.setText("Added: " + added.size() + "          ");
        solverAddedLabel.setEnabled(true);
        solverRemovedLabel.setText("Removed: " + removed.size() + "          ");
        solverRemovedLabel.setEnabled(true);
        solverScoreLabel.setText("Score: " + cost);
        solverScoreLabel.setEnabled(true);
        solvedModel = model.createSpecificCopy();
        solvedModel.addAll(added);
        solvedModel.removeAll(removed);
    }

    private class SolverListener implements AlloeProgressListener {

        public void finished() {
            onSolve();
        }

        public void progressChange(double newProgress) {
        }
    }

    private void onLoadMatrix() {
        pmRowsLabel.setText("Rows: " + matrix.getRowCount() + "          ");
        pmRowsLabel.setEnabled(true);
        pmColsLabel.setText("Columns: " + matrix.getColumnCount() + "          ");
        pmColsLabel.setEnabled(true);
        pmElemsLabel.setText("Elements: " + matrix.getElemCount());
        pmElemsLabel.setEnabled(true);
        saveProblemMatrix.setEnabled(true);
        if (useStandardSolver.isSelected()) {
            consistSolver = new ConsistSolver(matrix);
            consistSolver.addProgressListener(new SolverListener());
            solverMonitor.setProcess(consistSolver);
        }
    }

    private class PMMonitorListener implements ProcessMonitorListener {

        public boolean onResume(ProcessMonitor pm) {
            return true;
        }

        public boolean onStart(ProcessMonitor pm) {
            return true;
        }
    }

    private class PMListener implements AlloeProgressListener {

        public void finished() {
            matrix = consistProblem.mat;
            onLoadMatrix();
        }

        public void progressChange(double newProgress) {
        }
    }

    private void prepareProblemMatrix() {
        if (useStandardSolver.isSelected()) {
            consistProblem = new ConsistProblem(logic, model);
            consistProblem.addProgressListener(new PMListener());
            problemMatrixMonitor.setProcess(consistProblem);
        } else if (logic != null) { // && useGrowingSolver.isSelected()
            growingSolver = new GrowingSolver(logic, model);
            growingSolver.addProgressListener(new SolverListener());
            solverMonitor.setProcess(growingSolver);
        }
    }

    private void saveModelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveModelActionPerformed
        if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
            try {
                ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileChooser.getSelectedFile()));
                oos.writeObject(model);
                oos.close();
            } catch (IOException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not save model", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_saveModelActionPerformed

    private void openModelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openModelActionPerformed
        if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            try {
                ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileChooser.getSelectedFile()));
                Object o = ois.readObject();
                if (!(o instanceof Model)) {
                    JOptionPane.showMessageDialog(this, "Invalid format", "Could not open model", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                model = (Model) o;
                onModelLoad();
            } catch (IOException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open model", JOptionPane.ERROR_MESSAGE);
            } catch (ClassNotFoundException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open model", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_openModelActionPerformed

    private void saveLogicButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveLogicButtonActionPerformed
        if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
            try {
                BufferedWriter bw = new BufferedWriter(new FileWriter(fileChooser.getSelectedFile()));
                bw.write(logic.toString());
                bw.close();
            } catch (IOException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not save logic file", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_saveLogicButtonActionPerformed

    private void processLogicButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_processLogicButtonActionPerformed
        try {
            logic = new Logic(logicDescription.getText());
            onLoadLogic();
        } catch (IllegalArgumentException x) {
            JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open logic", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_processLogicButtonActionPerformed

    private void modelRelationshipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modelRelationshipActionPerformed
        String graphName = modelRelationship.getSelectedItem().toString();
        Graph graph = model.getGraphByName(graphName);
        modelLinksLabel.setText("Model Links: " + graph.linkCount());
    }//GEN-LAST:event_modelRelationshipActionPerformed

    private void initProbModelBuilder() {
        Collection<String> logicNames = logic.getRelations();
        HashMap<String, Classifier> classifs = new HashMap<String, Classifier>(logicNames.size());
        HashMap<String, String> dataSetToLogicName = new HashMap<String, String>(logicNames.size());
        for (int i = 0; i < logicConnectionTable.getModel().getRowCount(); i++) {
            classifs.put(logicConnectionTable.getModel().getValueAt(i, 1).toString(),
                    classifierSet.get(logicConnectionTable.getModel().getValueAt(i, 2).toString()));
            dataSetToLogicName.put(logicConnectionTable.getModel().getValueAt(i, 1).toString(),
                    logicConnectionTable.getModel().getValueAt(i, 0).toString());
        }
        probModelBuilder.setClassifiers(classifs);
        probModelBuilder.setDataSetToLogicName(dataSetToLogicName);
    }

    private void onModelLoad() {
        if (logic != null) {
            model.addCompulsorys(logic);
            prepareProblemMatrix();
        }
        modelRelationShipLabel.setEnabled(true);
        modelRelationship.setModel(new DefaultComboBoxModel(model.getGraphNames()));
        modelRelationship.setSelectedIndex(0);
        modelRelationship.setEnabled(true);
        String graphName = modelRelationship.getSelectedItem().toString();
        Graph graph = model.getGraphByName(graphName);
        modelLinksLabel.setText("Model Links: " + graph.linkCount());
        modelLinksLabel.setEnabled(true);
        visualizeModel.setEnabled(true); // TODO change to is JGraph in classpath
        saveModel.setEnabled(true);

        standardModel = model.createBlankSpecificCopy();
        // Prepare standard model
        Vector<String> rels = new Vector<String>();
        Iterator<String> graphNameIter = model.graphNameIterator();
        while (graphNameIter.hasNext()) {
            String s = graphNameIter.next();
            if (model.getGraphByName(s) instanceof ProbabilityGraph) {
                rels.add(s);
                standardModelTermPairs.put(s, "");
            }
        }
        standardRelationship.setModel(new DefaultComboBoxModel(rels));
        standardRelationship.setEnabled(true);
        standardOpenTermPairs.setEnabled(true);
        standardTermPairLabel.setEnabled(true);
    }

    private class ModelProcessListener implements AlloeProgressListener {

        public void finished() {
            model = probModelBuilder.model;
            onModelLoad();
        }

        public void progressChange(double newProgress) {
        }
    }

    private class ModelPMListener implements ProcessMonitorListener {

        public boolean onStart(ProcessMonitor pm) {
            initProbModelBuilder();
            return true;
        }

        public boolean onResume(ProcessMonitor pm) {
            probModelBuilder = (ProbModelBuilder) pm.getProcess();
            return true;
        }
    }

    private void isTrainingCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_isTrainingCheckActionPerformed
        isTraining = isTrainingCheck.isSelected();
        String pat = featureVectorPatternSet.getSelectedItem().toString();
        if (corpus != null && patternSets.size() == fvTermSetFileName.size()) {
            initFeatureVectorProcess();
        }
    }//GEN-LAST:event_isTrainingCheckActionPerformed

    private void prepareLogicConnections() {
        TableColumn fvCol = logicConnectionTable.getColumnModel().getColumn(1);
        JComboBox fvCombo = new JComboBox();
        Iterator<String> fviter = dataSet.instances.keySet().iterator();
        String defFV = "";
        while (fviter.hasNext()) {
            defFV = fviter.next();
            fvCombo.addItem(defFV);
        }
        fvCol.setCellEditor(new DefaultCellEditor(fvCombo));

        TableColumn clCol = logicConnectionTable.getColumnModel().getColumn(2);
        JComboBox clCombo = new JComboBox();
        Iterator<String> cliter = classifierSet.keySet().iterator();
        String defCl = "";
        while (cliter.hasNext()) {
            defCl = cliter.next();
            clCombo.addItem(defCl);
        }
        clCol.setCellEditor(new DefaultCellEditor(clCombo));

        Iterator<String> relIter = logic.getRelations().iterator();
        DefaultTableModel dtm = (DefaultTableModel) logicConnectionTable.getModel();
        while (dtm.getRowCount() > 0) {
            dtm.removeRow(0);
        }
        while (relIter.hasNext()) {
            Object[] os = new Object[3];
            os[0] = relIter.next();
            os[1] = dataSet.instances.containsKey(os[0]) ? os[0] : defFV;
            os[2] = classifierSet.containsKey(os[0]) ? os[0] : defCl;
            dtm.addRow(os);
        }
    }

    private void prepareProbModelBuilder() {
        probModelBuilder = new ProbModelBuilder(logic, dataSet, null, null);
        probModelBuilder.addProgressListener(new ModelProcessListener());
        probModelBuilderMonitor.setProcess(probModelBuilder);
        initProbModelBuilder();
        probModelBuilderMonitor.addProcessMonitorListener(new ModelPMListener());
    }

    private void onLoadLogic() {
        if (dataSet != null && classifierSet != null) {
            prepareLogicConnections();
        }
        if (dataSet != null) {
            prepareProbModelBuilder();
        }
        saveLogicButton.setEnabled(true);
        logicDescription.setText(logic.toString());
        if (model != null) {
            prepareProblemMatrix();
        }
    }

    private void openLogicActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openLogicActionPerformed
        if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            try {
                logic = new Logic(fileChooser.getSelectedFile());
                onLoadLogic();
            } catch (IllegalArgumentException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open logic file", JOptionPane.ERROR_MESSAGE);
                return;
            } catch (IOException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open logic file", JOptionPane.ERROR_MESSAGE);
                return;
            }
        }
    }//GEN-LAST:event_openLogicActionPerformed

    private void saveClassifierButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveClassifierButtonActionPerformed
        if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
            try {
                ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileChooser.getSelectedFile()));
                oos.writeObject(classifierSet);
                oos.close();
            } catch (IOException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not save classifier set", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_saveClassifierButtonActionPerformed

    private void openClassifierButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openClassifierButtonActionPerformed
        if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            try {
                ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileChooser.getSelectedFile()));
                Object o = ois.readObject();
                if (!(o instanceof Map)) {
                    JOptionPane.showMessageDialog(this, "Invalid Format", "Could not open classifier set", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                classifierSet = (Map<String, Classifier>) o;
            } catch (IOException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open classifier set", JOptionPane.ERROR_MESSAGE);
            } catch (ClassNotFoundException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open classifier set", JOptionPane.ERROR_MESSAGE);
            }
        }
        
    }//GEN-LAST:event_openClassifierButtonActionPerformed

    private void startTrainingButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startTrainingButtonActionPerformed
        try {
            Iterator<Map.Entry<String, Instances>> ei = dataSet.instances.entrySet().iterator();
            while (ei.hasNext()) {
                Map.Entry<String, Instances> ei2 = ei.next();
                String relationship = ei2.getKey();
                if (!dataSet.isTraining(relationship)) {
                    continue;
                }
                Instances instances = ei2.getValue();
                instances.setClassIndex(instances.numAttributes() - 1);
                String[] opts = new String[1];
                opts[0] = classifierParameters.getText();
                String s = classifier.getSelectedItem().toString();
                Classifier c = Classifier.forName(classifierNameToFullName.get(classifier.getSelectedItem().toString()),
                        opts);
                wekaOutput.append("Building classifier for relationship: " + relationship);
                c.buildClassifier(instances);
                wekaOutput.append(" ...OK!\n");
                wekaOutput.append(c.toString());
                classifierSet.put(relationship, c);
            }
            saveClassifierButton.setEnabled(true);
        } catch (Exception x) {
            x.printStackTrace();
        }
    }//GEN-LAST:event_startTrainingButtonActionPerformed

    private void classifierActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_classifierActionPerformed
        if (classifier.getSelectedItem().toString().equals("Other")) {
            String displayName = JOptionPane.showInputDialog(this, "Enter Display Name");
            if (displayName == null) {
                return;
            }
            // TODO destroy duplication
            String className = "";
            boolean classOK = false;
            while (className != null && !classOK) {
                className = JOptionPane.showInputDialog(this, "Enter Class Name");

                if (className == null) {
                    return;
                }
                try {
                    classOK = weka.classifiers.Classifier.class.isAssignableFrom(Class.forName(className));
                } catch (ClassNotFoundException x) {
                    classOK = false;
                }

                if (!classOK) {
                    JOptionPane.showMessageDialog(this, "Please enter a class name. Example: \"weka.classifiers.bayes.NaiveBayes\"", "Invalid classifier name or classifier not found", JOptionPane.ERROR_MESSAGE);
                }
            }
            if (className != null) {
                classifierNameToFullName.put(displayName, className);
                DefaultComboBoxModel dcbm = (DefaultComboBoxModel) classifier.getModel();
                dcbm.insertElementAt(displayName, dcbm.getIndexOf("Other"));
                classifier.setSelectedItem(displayName);
            }
        }
        classifierParameters.setText("");
    }//GEN-LAST:event_classifierActionPerformed

    private void saveDataSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveDataSetActionPerformed
        if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
            try {
                ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileChooser.getSelectedFile()));
                oos.writeObject(dataSet);
                oos.close();
            } catch (IOException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not save data set", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_saveDataSetActionPerformed

    private void onDataSetLoad() {
        featureVectorPatternSet.setModel(new DefaultComboBoxModel(dataSet.instances.keySet().toArray()));
        saveDataSet.setEnabled(true);
        standardTermSetLabel.setText("Term Set: <From Data Set>");
        standardTermList = dataSet.termSet;
    }

    private void openDataSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openDataSetActionPerformed
        if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            try {
                ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileChooser.getSelectedFile()));
                Object o = ois.readObject();
                if (!(o instanceof DataSet)) {
                    JOptionPane.showMessageDialog(this, "Invalid Format", "Could not open data set", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                dataSet = (DataSet) o;
                onDataSetLoad();
            } catch (IOException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open data set", JOptionPane.ERROR_MESSAGE);
            } catch (ClassNotFoundException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open data set", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_openDataSetActionPerformed

    private class FeatureVectorListener implements AlloeProgressListener {

        public void progressChange(double newProgress) {

        }

        public void finished() {
            onDataSetLoad();
        }
    }

    private class FVPMListener implements ProcessMonitorListener {

        public boolean onStart(ProcessMonitor pm) {
            return initFeatureVectorProcess();
        }

        public boolean onResume(ProcessMonitor pm) {
            return true;
        }
    }

    private boolean initFeatureVectorProcess() {
        try {
            Vector<TermPairSet> tps = new Vector<TermPairSet>();
            for (String rel : patternSets.keySet()) {
                if (!isTraining) {
                    if (rel == null) {
                        return false;
                    }
                    ObjectInputStream ios = new ObjectInputStream(new FileInputStream(fvTermSetFileName.get(rel)));
                    Object o = ios.readObject();
                    if (!(o instanceof TermPairSet)) {
                        JOptionPane.showMessageDialog(this, "Invalid format", "Could not open term set", JOptionPane.ERROR_MESSAGE);
                        return false;
                    }
                    tps.add((TermPairSet) o);
                }
            }
            FeatureVectorFormer fvf = new FeatureVectorFormer(new Vector<String>(patternSets.keySet()),
                    new Vector<PatternSet>(patternSets.values()), corpus, tps);
            fvf.dataSet = dataSet;
            featureVectorProcess = fvf;
            if (fvListener == null) {
                fvListener = new FeatureVectorListener();
            }
            fvf.addProgressListener(fvListener);
            featureVectorFormerMonitor.setProcess(fvf);
            for(String rel : patternSets.keySet())
                dataSet.setTraining(rel, isTrainingCheck.isSelected());
            return true;
        } catch (IOException x) {
            JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open term set", JOptionPane.ERROR_MESSAGE);
            return false;
        } catch (ClassNotFoundException x) {
            JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open term set", JOptionPane.ERROR_MESSAGE);
            return false;
        }

    }

    private void featureOpenTermPairsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_featureOpenTermPairsActionPerformed
        if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            String pat = featureVectorPatternSet.getSelectedItem().toString();
            String rel = featureVectorRelationship.getText();
            fvTermSetFileName.put(rel,
                    fileChooser.getSelectedFile());
            featureVectorTermPairLabel.setText("Term Pair Set: " + fileChooser.getSelectedFile().getName());
            if (corpus != null && patternSets.size() == fvTermSetFileName.size()) {
                initFeatureVectorProcess();
            }
        }
    }//GEN-LAST:event_featureOpenTermPairsActionPerformed

    private void featureVectorPatternSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_featureVectorPatternSetActionPerformed
        featureVectorRelationship.setText(featureVectorPatternSet.getSelectedItem().toString());
    }//GEN-LAST:event_featureVectorPatternSetActionPerformed
    private HashMap<String, String> classifierNameToFullName;

    public Vector<String> getClassifierNames() {
        Vector<String> r = new Vector<String>(8);
        classifierNameToFullName = new HashMap<String, String>(7);
        classifierNameToFullName.put("Bayesian Network", "weka.classifiers.bayes.BayesNet");
        classifierNameToFullName.put("Decision Tree", "weka.classifiers.trees.J48");
        classifierNameToFullName.put("Rule Learner", "weka.classifiers.rules.JRip");
        classifierNameToFullName.put("Linear Regression", "weka.classifiers.functions.LinearRegression");
        classifierNameToFullName.put("Multilayer Perceptron", "weka.classifiers.functions.MultilayerPerceptron");
        classifierNameToFullName.put("Naive Bayes", "weka.classifiers.bayes.NaiveBayes");
        classifierNameToFullName.put("SVM", "weka.classifiers.functions.SMO");

        r.add("SVM");
        r.add("Naive Bayes");
        r.add("Bayesian Network");
        r.add("Multilayer Perceptron");
        r.add("Linear Regression");
        r.add("Rule Learner");
        r.add("Decision Tree");
        r.add("Other");

        return r;
    }

    private void patternViewerRelationshipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_patternViewerRelationshipActionPerformed
        onPatternSetLoad(patternViewerRelationship.getSelectedItem().toString(), false);
    }//GEN-LAST:event_patternViewerRelationshipActionPerformed

    private void onPatternSetLoad(String relationship) {
        onPatternSetLoad(relationship, true);
    }

    private void onPatternSetLoad(String relationship, boolean select) {
        DefaultComboBoxModel dcbm = (DefaultComboBoxModel) patternViewerRelationship.getModel();
        if (dcbm.getIndexOf(relationship) == -1) {
            dcbm.addElement(relationship);
        }
        dcbm = (DefaultComboBoxModel) featureVectorPatternSet.getModel();
        if (dcbm.getIndexOf(relationship) == -1) {
            dcbm.addElement(relationship);
        }
        if (select) {
            patternViewerRelationship.setSelectedItem(relationship);
        }
        patternViewerRelationship.setEnabled(true);
        patternViewerRelationshipLabel.setEnabled(true);
        savePatternSet.setEnabled(true);
        PatternSet ps = patternSets.get(relationship);
        if (ps == null) {
            return;
        }

        totalPatternsLabel.setText("Total Patterns: " + ps.size());

        DefaultTableModel dtm = (DefaultTableModel) patternTable.getModel();
        Object[][] o = new Object[ps.size()][2];
        DecimalFormat df = new DecimalFormat("0.00000000");
        Iterator<Map.Entry<Pattern, Double>> iter = ps.entrySet().iterator();
        int i = 0;
        while (iter.hasNext()) {
            Map.Entry<Pattern, Double> e = iter.next();
            o[i][0] = e.getKey().toString();
            o[i++][1] = df.format(e.getValue().doubleValue());
        }
        String[] s = {"Pattern", "Score"};
        dtm.setDataVector(o, s);

    }

    private class PatternGeneratorListener implements PatternSetListener {

        private String getRelationship() {
            return ((PatternBuilder) patternGeneratorProgressMonitor.getProcess()).getRelationship();
        }

        /** Called whenever progress is made
         * @param newProgress The new progress percentage (as double between 0 and 1) */
        public void progressChange(double newProgress) {
        }

        /** Called when the process finishes */
        public void finished() {
            patternSets.put(getRelationship(), patternBuilderProcess.get(getRelationship()).patternScores);
            onPatternSetLoad(getRelationship());
        }

        public void patternGenerated(Pattern p, double score) {
            if (patternViewerRelationship.getSelectedItem().toString().equals(getRelationship())) {
                DefaultTableModel dtm = (DefaultTableModel) patternTable.getModel();
                Object[] row = new Object[2];
                row[0] = p.toString();
                NumberFormat df = new DecimalFormat("0.00000000");
                row[1] = df.format(score);
                dtm.addRow(row);
                if (patternBuilderProcess.get(getRelationship()) instanceof PatternSetBuilder) {
                    totalPatternsLabel.setText("Pattern Set Score: " +
                            df.format(((PatternSetBuilder) patternBuilderProcess.get(
                            getRelationship())).getSetScore()));
                } else {
                    totalPatternsLabel.setText("Total Patterns: " +
                            patternBuilderProcess.get(getRelationship()).patternScores.size());
                }
            }
        }

        public void patternDropped(Pattern p) {
            if (patternViewerRelationship.getSelectedItem().toString().equals(getRelationship())) {
                DefaultTableModel dtm = (DefaultTableModel) patternTable.getModel();
                int i;
                for (i = 0; i < dtm.getRowCount(); i++) {
                    if (dtm.getValueAt(i, 0).equals(p.toString())) {
                        break;
                    }
                }
                if (dtm.getRowCount() == i) {
                    throw new IllegalArgumentException("Asked to drop pattern not in table!");
                }
                dtm.removeRow(i);
            }
        }

        public void clearPatterns() {
            String[] s = {"Pattern", "Score"};
            patternTable.setModel(new DefaultTableModel(s, 0));
        }
    }

    private void savePatternSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_savePatternSetActionPerformed
        if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
            try {
                ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileChooser.getSelectedFile()));
                oos.writeObject(patternSets.get(patternViewerRelationship.getSelectedItem().toString()));
                oos.close();
            } catch (IOException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not save pattern set", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_savePatternSetActionPerformed

    private void openPatternSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openPatternSetActionPerformed
        if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            try {
                ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileChooser.getSelectedFile()));
                Object o = ois.readObject();
                if (!(o instanceof PatternSet)) {
                    JOptionPane.showMessageDialog(this, "Invalid format", "Could not open pattern set", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                PatternSet ps = (PatternSet) o;
                if (ps.getRelationship() == null) {
                    throw new NullPointerException();
                }
                patternSets.put(ps.getRelationship(), ps);
                onPatternSetLoad(ps.getRelationship());
            } catch (IOException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open pattern set", JOptionPane.ERROR_MESSAGE);
            } catch (ClassNotFoundException x) {
                JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open pattern set", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_openPatternSetActionPerformed

    private void patternBuilderMetricActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_patternBuilderMetricActionPerformed
        PatternBuilder pb = patternBuilderProcess.get(patternGeneratorRelationship.getSelectedItem().toString());
        if (pb != null) {
            pb.setPatternMetric(patternBuilderMetric.getSelectedItem().toString());
        }
    }//GEN-LAST:event_patternBuilderMetricActionPerformed

    private void initPatternBuilderProcess(String name, boolean set) {
        //if(!patternBuilderProcess.containsKey(name)) {
        try {
            ObjectInputStream ios = new ObjectInputStream(new FileInputStream(termSetFileName.get(name)));
            Object o = ios.readObject();
            if (!(o instanceof TermPairSet)) {
                JOptionPane.showMessageDialog(this, "Invalid format", "Could not open term set", JOptionPane.ERROR_MESSAGE);
                return;
            }
            PatternBuilder pb;
            if (set) {
                pb = new PatternSetBuilder(corpus, (TermPairSet) o, name, (Integer) bestPatternSetSize.getValue());
            } else {
                pb = new PatternBuilder(corpus, (TermPairSet) o,
                        (String) patternBuilderMetric.getSelectedItem(), name);
            }
            patternBuilderProcess.put(name, pb);
            if (pbListener == null) {
                pbListener = new PatternGeneratorListener();
            }
            pb.addProgressListener(pbListener);
            patternGeneratorProgressMonitor.setProcess(pb);
        } catch (IOException x) {
            JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open term set", JOptionPane.ERROR_MESSAGE);
        } catch (ClassNotFoundException x) {
            JOptionPane.showMessageDialog(this, x.getMessage(), "Could not open term set", JOptionPane.ERROR_MESSAGE);
        }
    //}
    }

    private void openTermPairSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openTermPairSetActionPerformed
        if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            termSetFileName.put(patternGeneratorRelationship.getSelectedItem().toString(),
                    fileChooser.getSelectedFile());
            termPairSetLabel.setText("Term Pair Set: " + fileChooser.getSelectedFile().getName());
            if (corpus != null) {
                initPatternBuilderProcess(patternGeneratorRelationship.getSelectedItem().toString(),
                        bestPatternSet.isSelected());
            }
        }
    }//GEN-LAST:event_openTermPairSetActionPerformed

    private void patternGeneratorRelationshipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_patternGeneratorRelationshipActionPerformed
        if (patternGeneratorRelationship.getSelectedItem().equals("New...")) {
            String name = JOptionPane.showInputDialog(this, "New Relation", "");
            if (name == null) {
                patternGeneratorRelationship.setSelectedIndex(0);
                return;
            }
            ((DefaultComboBoxModel) patternGeneratorRelationship.getModel()).insertElementAt(name, 0);
            ((DefaultComboBoxModel) patternViewerRelationship.getModel()).insertElementAt(name, 0);
            ((DefaultComboBoxModel) featureVectorPatternSet.getModel()).insertElementAt(name, 0);
            if (patternGeneratorRelationship.getItemAt(1).equals("")) {
                patternGeneratorRelationship.removeItemAt(1);
            }

            patternGeneratorRelationship.setSelectedItem(name);
            patternViewerRelationship.setSelectedItem(name);
        }

        termPairSetLabel.setEnabled(true);
        File f = termSetFileName.get(patternGeneratorRelationship.getSelectedItem().toString());
        termPairSetLabel.setText("Term Pair Set: " + (f == null ? "" : f.getName()));
        openTermPairSet.setEnabled(true);
        PatternBuilder pb = (PatternBuilder) patternGeneratorProgressMonitor.getProcess();
        if (pb == null || !pb.isRunning()) {
            patternGeneratorProgressMonitor.setProcess(patternBuilderProcess.get(patternGeneratorRelationship.getSelectedItem().toString()));
        }
        
    }//GEN-LAST:event_patternGeneratorRelationshipActionPerformed

    private void setIndexButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setIndexButtonActionPerformed
        int oldFMS = fileChooser.getFileSelectionMode();
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fileChooser.setAcceptAllFileFilterUsed(false);
        if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
            fileChooser.setFileSelectionMode(oldFMS);
            fileChooser.setAcceptAllFileFilterUsed(true);
            return;
        }
        fileChooser.setFileSelectionMode(oldFMS);
        fileChooser.setAcceptAllFileFilterUsed(true);
        corpusIndexFile = fileChooser.getSelectedFile();
        indexLocationLabel.setText("Index Location: " + fileChooser.getSelectedFile().getName());
        if (corpusTextFile != null && corpusTermSetFile != null &&
                corpusIndexFile != null) {
            prepareCorpusLoader();
        }
    }//GEN-LAST:event_setIndexButtonActionPerformed

    private void prepareCorpusLoader() {
        try {
            ObjectInputStream ois = new ObjectInputStream(new FileInputStream(corpusTermSetFile));
            Object o = ois.readObject();
            if (!(o instanceof TermList)) {
                JOptionPane.showMessageDialog(this, "Invalid File Format", "Could not open term set", JOptionPane.ERROR_MESSAGE);
                return;
            }
            CorpusFile corpusFile;
            if (corpusTextFile.matches(".*\\.zip")) {
                corpusFile = new ZipCorpusFile(corpusTextFile);
            } else {
                corpusFile = new TextCorpusFile(corpusTextFile);
            }
            corpusLoader = new CorpusLoader((TermList) o, corpusFile, corpusIndexFile);
            corpusLoader.setContextSize((Integer) contextSizeSpinner.getValue());
            corpusLoader.setMaxSketchSize((Integer) sketchSizeSpinner.getValue());
            indexerProgressMonitor.setProcess(corpusLoader);
            if (clProgListener == null) {
                clProgListener = new CorpusLoaderProgressListener();
            }
            corpusLoader.addProgressListener(clProgListener);

        } catch (IOException x) {
            JOptionPane.showMessageDialog(this, x.getMessage(), "Could not initialize indexer", JOptionPane.ERROR_MESSAGE);
        } catch (ClassNotFoundException x) {
            JOptionPane.showMessageDialog(this, x.getMessage(), "Could not initialize indexer", JOptionPane.ERROR_MESSAGE);
        }
    }

    private class CorpusTableModel extends AbstractTableModel {

        public int getColumnCount() {
            return 2;
        }

        public int getRowCount() {
            return corpus == null ? 0 : corpus.terms.size();
        }

        public Object getValueAt(int i, int j) {
            if (j == 0) {
                return corpus.terms.get(i);
            } else if (j == 1) {
                return corpus.getHitsForTerm(corpus.terms.get(i));
            } else {
                assert false;
                return null;
            }
        }

        public String getColumnName(int j) {
            if (j == 0) {
                return "Term";
            } else if (j == 1) {
                return "Frequency";
            } else {
                assert false;
                return null;
            }
        }

        public Class getColumnClass(int j) {
            if (j == 0) {
                return String.class;
            }
            if (j == 1) {
                return Integer.class;
            } else {
                return null;
            }
        }
    }

    private void onCorpusLoad() {
        corpusTotalLabel.setText("Total Contexts: " + corpus.getTotalDocs());
        corpusDisplayTableModel.fireTableDataChanged();
        corpusDisplay.revalidate();
        dataSet = new DataSet(corpus.terms);
    }

    private void openIndexedCorpusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openIndexedCorpusActionPerformed
        try {
            int oldFMS = fileChooser.getFileSelectionMode();
            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            fileChooser.setAcceptAllFileFilterUsed(false);
            if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
                fileChooser.setFileSelectionMode(oldFMS);
                fileChooser.setAcceptAllFileFilterUsed(true);
                return;
            }
            fileChooser.setFileSelectionMode(oldFMS);
            fileChooser.setAcceptAllFileFilterUsed(true);
            corpus = Corpus.openCorpus(fileChooser.getSelectedFile());
            onCorpusLoad();
        } catch (IOException x) {
            JOptionPane.showMessageDialog(this, x.getMessage(), "Could not load corpus", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_openIndexedCorpusActionPerformed

    private class CorpusLoaderProgressListener implements AlloeProgressListener {

        public void finished() {
            //corpus = corpusLoader.corpus;
            AlloeProcess p = indexerProgressMonitor.getProcess();
            assert p instanceof CorpusLoader;
            corpus = ((CorpusLoader) p).corpus;
            onCorpusLoad();
        }

        public void progressChange(double newProgress) {
        }
    }

    private void openCorpusTermSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openCorpusTermSetActionPerformed
        if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
            return;
        }
        corpusTermSetFile = fileChooser.getSelectedFile();
        termSetLabel.setText("Term Set: " + fileChooser.getSelectedFile().getName());
        if (corpusTextFile != null && corpusTermSetFile != null &&
                corpusIndexFile != null) {
            prepareCorpusLoader();
        }
    }//GEN-LAST:event_openCorpusTermSetActionPerformed

    private void openCorpusTextFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openCorpusTextFileActionPerformed
        if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
            return;
        }
        corpusTextFile = fileChooser.getSelectedFile().getAbsolutePath();
        textFileLabel.setText("Text File: " + fileChooser.getSelectedFile().getName());
        if (corpusTextFile != null && corpusTermSetFile != null &&
                corpusIndexFile != null) {
            prepareCorpusLoader();
        }
    }//GEN-LAST:event_openCorpusTextFileActionPerformed

    private void viewContextsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewContextsButtonActionPerformed
        int row = corpusDisplay.getSelectedRow();
        if (row == -1) {
            JOptionPane.showMessageDialog(this, "Please select a term", "Cannot show contexts", JOptionPane.WARNING_MESSAGE);
            return;
        }
        String term = (String) corpusDisplay.getValueAt(row, 0);
        Iterator<Corpus.Hit> hitIter = corpus.getContextsForTerm(term);
        ViewContextsDialog vcd = new ViewContextsDialog(this, true);
        while (hitIter.hasNext()) {
            vcd.addListItem(hitIter.next().getText());
        }
        vcd.setVisible(true);
}//GEN-LAST:event_viewContextsButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new AlloeMain().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton allPatterns;
    private javax.swing.JRadioButton bestPatternSet;
    private javax.swing.JSpinner bestPatternSetSize;
    private javax.swing.JComboBox classifier;
    private javax.swing.JTextField classifierParameters;
    private javax.swing.JTable confusionMatrixPost;
    private javax.swing.JTable confusionMatrixPre;
    private javax.swing.JSpinner contextSizeSpinner;
    private javax.swing.JTable corpusDisplay;
    private javax.swing.JScrollPane corpusDisplayScroll;
    private javax.swing.JLabel corpusTotalLabel;
    private javax.swing.JLabel fMeasurePostLabel;
    private javax.swing.JLabel fMeasurePreLabel;
    private javax.swing.JButton featureOpenTermPairs;
    private nii.alloe.gui.ProcessMonitor featureVectorFormerMonitor;
    private javax.swing.JComboBox featureVectorPatternSet;
    private javax.swing.JTextField featureVectorRelationship;
    private javax.swing.JLabel featureVectorTermPairLabel;
    private javax.swing.JLabel indexLocationLabel;
    private nii.alloe.gui.ProcessMonitor indexerProgressMonitor;
    private javax.swing.JCheckBox isTrainingCheck;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable logicConnectionTable;
    private javax.swing.JTextArea logicDescription;
    private javax.swing.JLabel logicLabel;
    private javax.swing.JLabel maxSketchLabel;
    private javax.swing.JLabel metricLabel;
    private javax.swing.JLabel modelLinksLabel;
    private javax.swing.JLabel modelRelationShipLabel;
    private javax.swing.JComboBox modelRelationship;
    private javax.swing.JButton openClassifierButton;
    private javax.swing.JButton openCorpusTermSet;
    private javax.swing.JButton openCorpusTextFile;
    private javax.swing.JButton openDataSet;
    private javax.swing.JButton openIndexedCorpus;
    private javax.swing.JButton openLogic;
    private javax.swing.JButton openModel;
    private javax.swing.JButton openPatternSet;
    private javax.swing.JButton openProblemMatrix;
    private javax.swing.JButton openStandardModel;
    private javax.swing.JButton openTermPairSet;
    private javax.swing.JButton patternAdvanced;
    private javax.swing.JComboBox patternBuilderMetric;
    private javax.swing.ButtonGroup patternGenerationPolicy;
    private nii.alloe.gui.ProcessMonitor patternGeneratorProgressMonitor;
    private javax.swing.JComboBox patternGeneratorRelationship;
    private javax.swing.JTable patternTable;
    private javax.swing.JComboBox patternViewerRelationship;
    private javax.swing.JLabel patternViewerRelationshipLabel;
    private javax.swing.JLabel pmColsLabel;
    private javax.swing.JLabel pmElemsLabel;
    private javax.swing.JLabel pmRowsLabel;
    private javax.swing.JLabel precisionPostLabel;
    private javax.swing.JLabel precisionPreLabel;
    private nii.alloe.gui.ProcessMonitor probModelBuilderMonitor;
    private nii.alloe.gui.ProcessMonitor problemMatrixMonitor;
    private javax.swing.JButton processLogicButton;
    private javax.swing.JLabel recallPostLabel;
    private javax.swing.JLabel recallPreLabel;
    private javax.swing.JButton saveClassifierButton;
    private javax.swing.JButton saveDataSet;
    private javax.swing.JButton saveLogicButton;
    private javax.swing.JButton saveModel;
    private javax.swing.JButton savePatternSet;
    private javax.swing.JButton saveProblemMatrix;
    private javax.swing.JButton saveStandardModel;
    private javax.swing.JButton setIndexButton;
    private javax.swing.JSpinner sketchSizeSpinner;
    private javax.swing.JLabel solverAddedLabel;
    private nii.alloe.gui.ProcessMonitor solverMonitor;
    private javax.swing.ButtonGroup solverRadioGroup;
    private javax.swing.JLabel solverRemovedLabel;
    private javax.swing.JLabel solverScoreLabel;
    private javax.swing.JButton standardOpenTermPairs;
    private javax.swing.JButton standardOpenTermSet;
    private javax.swing.JComboBox standardRelationship;
    private javax.swing.JLabel standardTermPairLabel;
    private javax.swing.JLabel standardTermSetLabel;
    private javax.swing.JButton startTrainingButton;
    private javax.swing.JLabel termPairSetLabel;
    private javax.swing.JLabel termSetLabel;
    private javax.swing.JLabel textFileLabel;
    private javax.swing.JLabel totalPatternsLabel;
    private javax.swing.JRadioButton useGrowingSolver;
    private javax.swing.JCheckBox useLazyMatching;
    private javax.swing.JCheckBox useSketchingCheck;
    private javax.swing.JRadioButton useStandardSolver;
    private javax.swing.JButton viewContextsButton;
    private javax.swing.JButton visualizeModel;
    private javax.swing.JTextArea wekaOutput;
    // End of variables declaration//GEN-END:variables
    /**
     * Holds value of property corpusDisplayTableModel.
     */
    private CorpusTableModel corpusDisplayTableModel;

    /**
     * Getter for property corpusDisplayTableModel.
     * @return Value of property corpusDisplayTableModel.
     */
    public CorpusTableModel getCorpusDisplayTableModel() {
        if (corpusDisplayTableModel != null) {
            return this.corpusDisplayTableModel;
        } else {
            return corpusDisplayTableModel = new CorpusTableModel();
        }
    }

    /**
     * Setter for property corpusDisplayTableModel.
     * @param corpusDisplayTableModel New value of property corpusDisplayTableModel.
     */
    public void setCorpusDisplayTableModel(CorpusTableModel corpusDisplayTableModel) {
        this.corpusDisplayTableModel = corpusDisplayTableModel;
    }
}
